    using B.S.Data.MES.API.Applications.CangKu.Command;
using B.S.Domain.CangKu;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;
using System.Threading;
using System.Threading.Tasks;

namespace B.S.Data.MES.API.Applications.CangKu.CommandHandlers
{
    /// <summary>
    /// 处理删除储位命令
    /// </summary>
    public class DeleteChuWeiCommandHandler : IRequestHandler<DeleteChuWeiCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<ChuWei> _chuWeiRepository;
        
        /// <summary>
        /// 构造函数，注入仓储
        /// </summary>
        public DeleteChuWeiCommandHandler(IBaseRepository<ChuWei> chuWeiRepository)
        {
            _chuWeiRepository = chuWeiRepository;
        }
        
        /// <summary>
        /// 处理删除请求
        /// </summary>
        public async Task<APIRequst<int>> Handle(DeleteChuWeiCommand request, CancellationToken cancellationToken)
        {
            var chuWei = await _chuWeiRepository.GetById(request.ChuId);
            chuWei.isDel = true;
            var result = await _chuWeiRepository.Update(chuWei);
            
            return new APIRequst<int>
            {
                Code=RequstCode.成功,
                Msg=RequstCode.成功.ToString(),
            };
        }
    }
}